package com.ly.aidlpratice.handwritten

import android.os.IBinder
import android.os.Parcel
import android.os.RemoteException
import com.ly.aidlpratice.bean.Book

class ServerBookCallback(private val mService: IBinder) : IBookCallback {

    @Throws(RemoteException::class)
    override fun callback(book: Book) {
        val data = Parcel.obtain()
        try {
            data.writeInterfaceToken(BOOK_CALLBACK_TOKEN)
            book.writeToParcel(data, 0)
            mService.transact(TRANSACTION_CALLBACK, data, null, 0)
        } finally {
            data.recycle()
        }
    }

    override fun asBinder(): IBinder {
        return mService
    }
}